home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7222 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  54 lines

  1. Newsgroups: comp.lang.c
  2. Path: undergrad.math.uwaterloo.ca!clgonsal
  3. From: clgonsal@undergrad.math.uwaterloo.ca (Carl Laurence Gonsalves)
  4. Subject: Re: Watch out!  C "gotcha!"
  5. Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
  6. Message-ID: <DMvM31.1uw@undergrad.math.uwaterloo.ca>
  7. Date: Fri, 16 Feb 1996 16:06:37 GMT
  8. References: <4fthhh$7th@blackice.winternet.com> <4g01ss$hgj@sun001.spd.dsccc.com>
  9. Nntp-Posting-Host: cayley.uwaterloo.ca
  10. Organization: University of Waterloo
  11.  
  12. In article <4g01ss$hgj@sun001.spd.dsccc.com>,
  13. Mike McCarty <jmccarty@spd.dsccc.com> wrote:
  14. >In article <4fthhh$7th@blackice.winternet.com>,
  15. >Michael Schwarz <mschwarz@winternet.com> wrote:
  16. >)Many of you may already know this, but even after ten years of coding
  17. >)in C, this took my by surprise at first.  A co-worker and I were looking
  18. >)at some library C code where I work and we noticed that the "default"
  19. >)clause of one of the switches was misspelled as "defalt."
  20. >[stuff cut]
  21. >
  22. >)The thing that scares me the most about this is that either I've never before
  23. >)made this particular mistake or for the last ten years I've been leaving
  24. >)behind a number of ticking code bombs...
  25. >
  26. >I know of no way to make a compiler catch spelling mistakes on labels
  27. >except by doing what Pascal does - force declaration of labels. The
  28. >exact same problem (only worse) occurs in Fortran where misspelled
  29. >variables "declare themselves". There is no solution except to require
  30. >declarations.
  31.  
  32. It would also be possible for the compiler to warn about unused labels.
  33. I just tried it with Watcom C and it *does* warn about this. Hmmm... Yet
  34. another reason to turn on all warnings...
  35.  
  36. Here's the test program:
  37.  
  38. #include <stdio.h>
  39.  
  40. int
  41. main(){
  42.   puts( "foo" );
  43.   defalt:
  44.   puts( "bar" );
  45.  
  46.   return 0;
  47. }
  48.  
  49. -- 
  50.         Carl Laurence Gonsalves - clgonsal@undergrad.math.uwaterloo.ca
  51.                    Computer Science, University of Waterloo
  52.                http://www.undergrad.math.uwaterloo.ca/~clgonsal/
  53.                    http://www.csclub.uwaterloo.ca/~clgonsal/
  54.